Container.setupDefaults   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 11
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 10
dl 0
loc 11
ccs 2
cts 2
cp 1
crap 1
rs 9.9
c 0
b 0
f 0
1
import DataStorage from '@enbock/simple-storage/DataStorage';
2
import ListenerAdapter from '@enbock/state-value-observer/ListenerAdapter';
3
import ValueObserver from '@enbock/state-value-observer/ValueObserver';
4
import ThemesManager from './ThemesManager';
5
import ThemesRegistry, {Theme} from './ThemesRegistry';
6
7
class Container {
8
  registry: ThemesRegistry;
9
  currentThemeAdapter: ListenerAdapter<Theme>;
10
  currentTheme: ValueObserver<Theme>;
11
  manager: ThemesManager;
12
  storage: DataStorage;
13
14
  constructor() {
15 2
    this.storage = new DataStorage('theme', window.localStorage);
16 2
    this.registry = new ThemesRegistry();
17 2
    this.currentThemeAdapter = new ListenerAdapter<Theme>();
18 2
    this.currentTheme = new ValueObserver<Theme>(
19
      this.storage.loadData<Theme>(
20
        'currentTheme',
21
        {
22
          isBuildIn: true,
23
          name: 'Google',
24
          url: 'Theme/Google'
25
        }
26
      ),
27
      this.storage.attach<Theme>('currentTheme', this.currentThemeAdapter)
28
    );
29 2
    this.manager = new ThemesManager(this.currentTheme, this.registry);
30
31 2
    this.setupDefaults();
32
  }
33
34
  protected setupDefaults(): void {
35 2
    this.registry.registerTheme({
36
      isBuildIn: true,
37
      name: 'Google',
38
      url: 'Theme/Google'
39
    });
40 2
    this.registry.registerTheme({
41
      isBuildIn: true,
42
      name: 'Codefrog',
43
      url: 'Theme/Codefrog'
44
    });
45
  }
46
}
47
48
export default new Container();
49